//
//  MainViewController.swift
//  weibo
//
//  Created by apple on 16/2/20.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    let mainTabbar = MainTabBar()
    //监听点击黄色按钮
    @objc private func plusBtnDidClick() {
        
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        //由于系统的tabbar是只读属性 不能够直接设置 可以通过kvc的方式在运行时 替换身份
        setValue(mainTabbar, forKey: "tabBar")
        let actionName = "plusBtnDidClick"
        
        mainTabbar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
        
        addChildViewControllers()
    }
    
    
    
    private func addChildViewControllers() {
        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    //MARK： 添加单个控制器
    private func addChildViewController(vc: UIViewController, title:String, imageName: String) {
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
}
